﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;
using XQ.RequestOfficeSupplies.DAL.DAL.Common;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Model.Sys;
using XQ.RequestOfficeSupplies.WebAPI.Models;

namespace XQ.RequestOfficeSupplies.WebAPI.Controllers.System
{
    /// <summary>
    /// 操作日志接口
    /// </summary>
    public class LogController : ApiController
    {
        /// <summary>
        /// 获取日志列表
        /// </summary>
        /// <returns></returns>
        [Route("api/Log/GetLogList")]
        [HttpGet]
        public ResultModel GetLogList([FromUri]LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                searchModel = new LogSearchModel();
            }
            LogBll bll = new LogBll();

            ResultModel resultModel = new ResultModel();
            Pagination page = new Pagination();
            try
            {
                resultModel.success = true;
                resultModel.code = "10000";
                resultModel.message = "执行成功";
                resultModel.data = LogBll.Instance.GetSys_logs(searchModel, page); ;
                resultModel.page = page;
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }

        /// <summary>
        /// 获取错误日志列表
        /// </summary>
        /// <returns></returns>
        [Route("api/Log/GetErrLogList")]
        [HttpGet]
        public ResultModel GetErrLogList([FromUri]LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                searchModel = new LogSearchModel();
            }
            LogBll bll = new LogBll();

            ResultModel resultModel = new ResultModel();
            Pagination page = new Pagination();
            try
            {
                resultModel.success = true;
                resultModel.code = "10000";
                resultModel.message = "执行成功";
                resultModel.data = LogBll.Instance.GetSys_Errlogs(searchModel, page);
                resultModel.page = page;
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }
    }
}